/** CS2340 Spring 2011 Project
 *  Team: 40 Jiggawatt Hard Driver
 *  Suk Hwan Hong
 *  Rhys Saraceni
 *  Travis Cooper
 *  Luke Stubb
 *
 * @author 40 Jiggawatt Hard Driver
 * @version 1.0 
 */

// $codepro.audit.disable com.instantiations.assist.eclipse.analysis.audit.rule.effectivejava.alwaysOverridetoString.alwaysOverrideToString
package edu.gatech.jiggawatt.office.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Represents Treatment Record
 * @author 40 Jiggawatt Hard Driver
 * @version 1.0 
 */
public class TreatmentRecord implements Serializable, Comparable<TreatmentRecord> // $codepro.audit.disable declareDefaultConstructors
{
	
	private String treatingDoctor;
	private Date date;
	private Time time;
	private String attendingNurse;
	private DoctorsOrder order;
	private String chiefComplaint;
	private double bloodPressure;
	private double pulse;
	private double temperature;
	private double height;
	private double weight;
	private String diagnosis;
	private List<Bill> bills;
	private static final double BLOOD_TEST = 75; // $codepro.audit.disable numericLiterals
	private static final double URINE_TEST = 50; // $codepro.audit.disable numericLiterals
	private static final double IMMUNIZATION_TEST = 100; // $codepro.audit.disable numericLiterals


	/**
	 * Constructor for treatment record
	 * @param td treating doctor
	 * @param d date
	 * @param t time
	 * @param an attending nurse
	 * @param cc chief complaint
	 * @param bp blood pressure
	 * @param p pulse
	 * @param tp temperature
	 * @param ht height
	 * @param wt weight
	 * @param diag diagnostics
	 */
	public TreatmentRecord(String td, Date d, Time t, String an, String cc, double bp, double p, double tp, double ht, double wt, String diag)
	{
		treatingDoctor = td;
		date = d;
		time = t;
		attendingNurse = an;
		chiefComplaint = cc;
		bloodPressure = bp;
		pulse = p;
		temperature = tp;
		height = ht;
		weight = wt;
		diagnosis = diag;
		order = new DoctorsOrder();
		bills = new ArrayList<Bill>();
	}
	
	/**
	 * sets treating doctor
	 * @param treatingDoctor
	 */
	public void setTreatingDoctor(String treatingDoctor) {
		this.treatingDoctor = treatingDoctor;
	}
	
	/**
	 * gets treating doctor
	 * @return treating doctor
	 */
	public String getTreatingDoctor() {
		return treatingDoctor;
	}
	
	/**
	 * sets date
	 * @param date
	 */
	public void setDate(Date date) {
		this.date = date;
	}
	
	/**
	 * gets date
	 * @return date
	 */
	public Date getDate() {
		return date;
	}
	
	/**
	 * sets time
	 * @param time
	 */
	public void setTime(Time time) {
		this.time = time;
	}
	
	/**
	 * gets time
	 * @return time
	 */
	public Time getTime() {
		return time;
	}
	
	/**
	 * sets attending nurse
	 * @param attendingNurse
	 */
	public void setAttendingNurse(String attendingNurse) {
		this.attendingNurse = attendingNurse;
	}
	
	/**
	 * gets attending nurse
	 * @return attending nurse
	 */
	public String getAttendingNurse() {
		return attendingNurse;
	}
	
	/**
	 * sets doctor's order
	 * @param order
	 */
	public void setDoctorsOrder(DoctorsOrder order)
	{
		this.order = order;
	}
	
	/**
	 * gets doctor's order
	 * @return doctor's order
	 */
	public DoctorsOrder getDoctorsOrder()
	{
		return order;
	}
	
	/**
	 * sets chief complaint
	 * @param chiefComplaint
	 */
	public void setChiefComplaint(String chiefComplaint) {
		this.chiefComplaint = chiefComplaint;
	}
	
	/**
	 * gets chief complaint
	 * @return chief complaint
	 */
	public String getChiefComplaint() {
		return chiefComplaint;
	}

	/**
	 * sets blood pressure
	 * @param bloodPressure
	 */
	public void setBloodPressure(double bloodPressure) {
		this.bloodPressure = bloodPressure;
	}

	/**
	 * gets blood pressure
	 * @return blood pressure
	 */
	public double getBloodPressure() {
		return bloodPressure;
	}

	/**
	 * sets temperature
	 * @param temperature
	 */
	public void setTemperature(double temperature) {
		this.temperature = temperature;
	}

	/**
	 * gets temperature
	 * @return temperature
	 */
	public double getTemperature() {
		return temperature;
	}

	/**
	 * sets pulse
	 * @param pulse
	 */
	public void setPulse(double pulse) {
		this.pulse = pulse;
	}

	/**
	 * gets pulse
	 * @return pulse
	 */
	public double getPulse() {
		return pulse;
	}

	/**
	 * sets height
	 * @param height
	 */
	public void setHeight(double height) {
		this.height = height;
	}

	/**
	 * gets height
	 * @return height
	 */
	public double getHeight() {
		return height;
	}
	
	/**
	 * sets weight
	 * @param weight
	 */
	public void setWeight(double weight) {
		this.weight = weight;
	}

	/**
	 * gets weight
	 * @return weight
	 */
	public double getWeight() {
		return weight;
	}

	/**
	 * sets diagnosis
	 * @param diagnosis
	 */
	public void setDiagnosis(String diagnosis) {
		this.diagnosis = diagnosis;
	}

	/**
	 * gets diagnosis
	 * @return diagnosis
	 */
	public String getDiagnosis() {
		return diagnosis;
	}
	
	/**
	 * adds bill
	 * @param bill
	 */
	public void addBill(Bill bill){
		bills.add(bill);		
	}
	
	/**
	 * changes bill
	 * @param oldBill
	 * @param newBill
	 */
	public void changeBill(Bill oldBill, Bill newBill)
	{
		bills.remove(oldBill);
		bills.add(newBill);
	}
	
	/**
	 * removes bill
	 * @param bill
	 */
	public void removeBill(Bill bill)
	{
		bills.remove(bill);
	}

	/**
	 * compares to other treatment record
	 * @param tr other treatment record to compare
	 * @return 1 if greater, 0 if equals, -1 is less
	 */
	public int compareTo(TreatmentRecord tr) 
	{
		int dateCompare = date.compareTo(tr.getDate());
        
		if (0 == dateCompare)
		{
			return time.compareTo(tr.getTime());
		}
		
        return dateCompare;
    }
	
	/**
	 * checks for equality
	 * @param t other treatment record to check for equality
	 * @return true if equals, false otherwise
	 */
	public boolean equals(Object t) // $codepro.audit.disable checkTypeInEquals, com.instantiations.assist.eclipse.analysis.audit.rule.effectivejava.obeyEqualsContract.obeyGeneralContractOfEquals
	{
		TreatmentRecord tr = (TreatmentRecord) t;
		return (0 == date.compareTo(tr.getDate())) && (0 == time.compareTo(tr.getTime()));
	}
	
	/**
	 * returns string representation of treatment record
	 * @return string representation of treatment record
	 */
	public String toString()
	{
		return date + " " + time + " by " + treatingDoctor; // $codepro.audit.disable stringLiterals
	}
	
	/**
	 * calculates total amount of bill for treatment record
	 * @return total amount of bill for treatment record
	 */
	public double calculateTotal()
	{
		double total = 0;
		for (Bill b : bills)
		{
			total += b.getAmount();
		}
		
		if (order.isBloodTest())
		{
			total += BLOOD_TEST;
		}
		
		if (order.isUrineTest())
		{
			total += URINE_TEST;
		}
		
		if (order.isImmunizationTest())
		{
			total += IMMUNIZATION_TEST;
		}
		
		return total;
	}
	
	/**
	 * returns string format of each itemized bill
	 * @return string format of each itemized bill
	 */
	public String getItemizedBill()
	{
		String itemizedBill = "";
		
		for (Bill b : bills)
		{
			itemizedBill += b.getDescription() + ": $" + b.getAmount() + "\n"; // $codepro.audit.disable stringLiterals
		}
		
		if (order.isBloodTest())
		{
			itemizedBill += "Blood Test: $" + BLOOD_TEST + "\n"; // $codepro.audit.disable stringLiterals
		}
		
		if (order.isUrineTest())
		{
			itemizedBill += "Urine Test: $" + URINE_TEST + "\n"; // $codepro.audit.disable stringLiterals
		}
		
		if (order.isImmunizationTest())
		{
			itemizedBill += "Immunization Test: $" + IMMUNIZATION_TEST + "\n"; // $codepro.audit.disable stringLiterals
		}
		
		return itemizedBill;
	}
}